<!DOCTYPE html>

<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->

<!--[if IE 9]> <html lang="en" class="ie9"> <![endif]-->

<!--[if !IE]><!--> <html lang="en"> <!--<![endif]-->

<!-- BEGIN HEAD -->

<head>
    <base href="/hxhmanage/"/>
    <meta charset="utf-8" />

    <title>好洗欢管理平台</title>

    <meta content="width=device-width, initial-scale=1.0" name="viewport" />

    <meta content="" name="description" />

    <meta content="" name="author" />

    <!-- BEGIN GLOBAL MANDATORY STYLES -->

    <link href="css/vendor/bootstrap.min.css" rel="stylesheet" type="text/css"/>

    <link href="css/vendor/bootstrap-responsive.min.css" rel="stylesheet" type="text/css"/>

    <link href="css/vendor/font-awesome.min.css" rel="stylesheet" type="text/css"/>

    <link href="css/vendor/style-metro.css" rel="stylesheet" type="text/css"/>

    <link href="css/vendor/style.css" rel="stylesheet" type="text/css"/>

    <link href="css/vendor/style-responsive.css" rel="stylesheet" type="text/css"/>

    <link href="css/vendor/default.css" rel="stylesheet" type="text/css" id="style_color"/>

    <link href="css/vendor/uniform.default.css" rel="stylesheet" type="text/css"/>

    <!-- END GLOBAL MANDATORY STYLES -->

    <!-- BEGIN PAGE LEVEL STYLES -->

    <link rel="stylesheet" type="text/css" href="css/vendor/select2_metro.css" />

    <link rel="stylesheet" href="css/vendor/DT_bootstrap.css" />

    <link rel="stylesheet" href="css/vendor/bootstrap-modal.css" />


    <link rel="stylesheet" href="css/common/common.css" />

    <!-- END PAGE LEVEL STYLES -->

    <link rel="shortcut icon" href="images/logo.png" />


</head>
<body class="page-header-fixed page-sidebar-closed">
<!-- BEGIN HEADER -->

<div class="header navbar navbar-inverse navbar-fixed-top">

    <!-- BEGIN TOP NAVIGATION BAR -->

    <div class="navbar-inner">

        <div class="container-fluid">

            <!-- BEGIN LOGO -->

            <a class="brand" href="index.html" style="padding:0px;">

                <img src="images/logo.png" alt="logo" />

            </a>

            <!-- END LOGO -->

            <!-- BEGIN RESPONSIVE MENU TOGGLER -->

            <a href="javascript:;" class="btn-navbar collapsed" data-toggle="collapse" data-target=".nav-collapse">

                <img src="images/menu-toggler.png" alt="" />

            </a>

            <!-- END RESPONSIVE MENU TOGGLER -->

            <!-- BEGIN TOP NAVIGATION MENU -->



            <!-- END TOP NAVIGATION MENU -->

        </div>

    </div>

    <!-- END TOP NAVIGATION BAR -->

</div>
<!-- BEGIN CONTAINER -->

<div class="page-container row-fluid">

    <!-- BEGIN SIDEBAR -->

    <div class="page-sidebar nav-collapse collapse">

        <!-- BEGIN SIDEBAR MENU -->

        <ul class="page-sidebar-menu">

            <li>

                <!-- BEGIN SIDEBAR TOGGLER BUTTON -->

                <div class="sidebar-toggler hidden-phone"></div>

                <!-- BEGIN SIDEBAR TOGGLER BUTTON -->

            </li>



            <li>

                <a href="indexAction!setStrutsPage.action?pageFlag=order/ordermana.html">

                    <i class="icon-file-text"></i>

                    <span class="title">订单管理</span>

                </a>

            </li>

            <li class="active">

                <a href="indexAction!setStrutsPage.action?pageFlag=community/communityList.html">

                    <i class="icon-home"></i>

                    <span class="title">地址管理</span>

                </a>

            </li>
			<li >

                <a href="indexAction!setStrutsPage.action?pageFlag=diser/disermana.html">

                    <i class=" icon-user-md"></i>

                    <span class="title">配送人员管理</span>

                </a>

            </li>

            <li >

                <a href="indexAction!setStrutsPage.action?pageFlag=pro/product.html">

                    <i class="icon-barcode"></i>

                    <span class="title">产品管理</span>

                </a>

            </li>


        </ul>

        <!-- END SIDEBAR MENU -->

    </div>

    <!-- END SIDEBAR -->

    <!-- BEGIN PAGE -->

    <div class="page-content">

        <!-- BEGIN SAMPLE PORTLET CONFIGURATION MODAL FORM-->

        <div id="portlet-config" class="modal hide">

            <div class="modal-header">

                <button data-dismiss="modal" class="close" type="button"></button>

                <h3>portlet Settings</h3>

            </div>

            <div class="modal-body">

                <p>Here will be a configuration form</p>

            </div>

        </div>

        <!-- END SAMPLE PORTLET CONFIGURATION MODAL FORM-->

        <!-- BEGIN PAGE CONTAINER-->

        <div class="container-fluid">

            <!-- BEGIN PAGE HEADER-->

            <div class="row-fluid">

                <div class="span12">


                </div>

            </div>

            <!-- END PAGE HEADER-->

            <!-- BEGIN PAGE CONTENT-->

            <div class="row-fluid">

                <div class="span12">

                    <!-- BEGIN EXAMPLE TABLE PORTLET-->

                    <div class="portlet box light-grey">

                        <div class="portlet-title">

                            <div class="caption"><i class="icon-globe"></i>地址管理</div>

                            <div class="tools">

                                <a href="javascript:;" class="collapse"></a>

                                <!--<a href="#portlet-config" data-toggle="modal" class="config"></a>-->

                                <!--<a href="javascript:;" class="reload"></a>-->

                                <!--<a href="javascript:;" class="remove"></a>-->

                            </div>

                        </div>

                        <div class="portlet-body ">

                            <div class="span12 booking-search">
                                <div class="control-group span4">
                                    <label class="control-label">省</label>
                                    <div class="controls">

                                        <select id="province" class="large m-wrap" tabindex="1">
                                            <option value="">-请选择-</option>
                                        </select>

                                    </div>
                                </div>

                                <div class="control-group span4">
                                    <label class="control-label">市</label>
                                    <div class="controls">

                                        <select id="city" class="large m-wrap" tabindex="1">
                                            <option value="">-请选择-</option>
                                            <option value="">-请先选择省-</option>
                                        </select>

                                    </div>
                                </div>

                                <div class="control-group span4">
                                    <label class="control-label">区</label>
                                    <div class="controls">

                                        <select id="district" class="large m-wrap" tabindex="1">
                                            <option value="">-请选择-</option>
                                            <option value="">-请先选择市-</option>
                                        </select>

                                    </div>

                                </div>

                                <div class="clearfix">
                                    <div class="control-group span12">
                                        <label class="control-label">小区名称</label>
                                        <div class="controls">

                                            <input type="text" id="commName" class="large m-wrap" tabindex="1"/>

                                        </div>

                                    </div>
                                </div>

                                <div class="control-group">
                                    <button id="searchBtn" class="btn blue btn-block">搜索 <i class="m-icon-swapright m-icon-white"></i></button>
                                </div>
                            </div>

                            <div class="btn-group" style="font-size: 15px;">

                                <a class="btn blue" data-toggle="modal" id="editCommDIV">添加 <i class="icon-plus"></i></a>

                                <button id="freshBtn" class="btn red">

                                    刷新 <i class="icon-refresh"></i>

                                </button>

                            </div>


                            <table class="table table-striped table-bordered table-hover" id="sample_1">

                                <thead>

                                <tr>

                                    <th style="width:8px;"><input type="checkbox" class="group-checkable" data-set="#sample_1 div span .checkboxes" /></th>

                                    <th style="width:80px;">省</th>
                                    <th style="width:80px;">市</th>
                                    <th style="width:80px;">区</th>
                                    <th style="width:100px;">小区名称</th>
                                    <th style="width:100px;">小区描述</th>
                                    <th style="width:80px;">小区经度</th>
                                    <th style="width:80px;">小区纬度</th>
                                    <th style="width:80px;">小区负责人</th>
                                    <th style="width:100px;">操作</th>

                                </tr>

                                </thead>

                            </table>

                        </div>

                    </div>

                    <!-- END EXAMPLE TABLE PORTLET-->

                </div>

            </div>



            <!-- END PAGE CONTENT-->

        </div>

        <!-- END PAGE CONTAINER-->

    </div>

    <!-- END PAGE -->

</div>

<!-- BEGIN FOOTER -->

<div class="footer">

    <div class="footer-inner">



    </div>

    <div class="footer-tools">

			<span class="go-top">

			<i class="icon-angle-up"></i>

			</span>

    </div>

</div>

<div id="editComm" class="modal hide fade" data-width="760" data-backdrop="static">

    <form id="commnuityForm" class="form-horizontal">

        <input type="hidden" name="commId">

        <div class="modal-header">

            <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>

            <h3>添加小区</h3>

        </div>

        <div class="modal-body">


            <div class="control-group">

                <label class="control-label">省<span class="required">*</span></label>

                <div class="controls">

                    <select id="provinceEdit" name="provinceId" class="medium m-wrap">
                        <option value="">-请选择-</option>
                    </select>

                </div>

            </div>

            <div class="control-group">
                <label class="control-label">市<span class="required">*</span></label>

                <div class="controls">

                    <select id="cityEdit" name="cityId" class="medium m-wrap">
                        <option value="">-请选择-</option>
                        <option value="">-请先选择省-</option>
                    </select>

                </div>
            </div>
            <div class="control-group">

                <label class="control-label">区<span class="required">*</span></label>

                <div class="controls">

                    <select id="districtEdit" name="regionalId" class="medium m-wrap">
                        <option value="">-请选择-</option>
                        <option value="">-请先选择市-</option>
                    </select>

                </div>

            </div>

            <div class="control-group">

                <label class="control-label">小区名称<span class="required">*</span></label>

                <div class="controls">

                    <input name="commName" type="text" class="m-wrap medium" />

                </div>

            </div>

            <div class="control-group">

                <label class="control-label">小区描述&nbsp;&nbsp;</label>

                <div class="controls">

                    <input name="commDesc" type="text" class="m-wrap medium" />

                </div>

            </div>

            <div class="control-group">

                <label class="control-label">小区经纬度<span class="required">*</span></label>

                <div class="controls">

                    <input name="commLongLatitude" type="text" class="m-wrap medium" />

                </div>

            </div>

            <div class="control-group">

                <label class="control-label">小区负责人<span class="required">*</span></label>

                <div class="controls">

                    <input name="disId" id="disId" class="m-wrap medium select2">

                </div>

            </div>

        </div>

        <div class="modal-footer">

            <button type="button" data-dismiss="modal" class="btn">关闭</button>

            <button id="editCommBtn" type="button" class="btn blue">保存</button>

        </div>

    </form>

</div>

<!-- END FOOTER -->

<!-- END CONTAINER -->


<!-- BEGIN JAVASCRIPTS(Load javascripts at bottom, this will reduce page load time) -->

<!-- BEGIN CORE PLUGINS -->

<script src="js/vendor/jquery-1.10.1.min.js" type="text/javascript"></script>

<script src="js/vendor/jquery-migrate-1.2.1.min.js" type="text/javascript"></script>

<!-- IMPORTANT! Load jquery-ui-1.10.1.custom.min.js before bootstrap.min.js to fix bootstrap tooltip conflict with jquery ui tooltip -->

<script src="js/vendor/jquery-ui-1.10.1.custom.min.js" type="text/javascript"></script>

<script src="js/vendor/bootstrap.min.js" type="text/javascript"></script>

<!--[if lt IE 9]>

<script src="js/vendor/excanvas.min.js"></script>

<script src="js/vendor/respond.min.js"></script>

<![endif]-->

<script src="js/vendor/jquery.slimscroll.min.js" type="text/javascript"></script>

<script src="js/vendor/jquery.blockui.min.js" type="text/javascript"></script>

<script src="js/vendor/jquery.cookie.min.js" type="text/javascript"></script>

<script src="js/vendor/jquery.uniform.min.js" type="text/javascript" ></script>

<!-- END CORE PLUGINS -->

<!-- BEGIN PAGE LEVEL PLUGINS -->

<script type="text/javascript" src="js/vendor/jquery.validate.min.js"></script>

<script type="text/javascript" src="js/vendor/additional-methods.min.js"></script>

<script type="text/javascript" src="js/vendor/select2.min.js"></script>

<script type="text/javascript" src="js/vendor/chosen.jquery.min.js"></script>

<script type="text/javascript" src="js/vendor/jquery.dataTables.js"></script>

<script type="text/javascript" src="js/vendor/DT_bootstrap.js"></script>

<script type="text/javascript" src="js/vendor/bootstrap-modal.js"></script>

<script type="text/javascript" src="js/vendor/bootstrap-modalmanager.js"></script>

<script type="text/javascript" src="js/vendor/fnReloadAjax.js"></script>

<!-- END PAGE LEVEL PLUGINS -->

<!-- BEGIN PAGE LEVEL SCRIPTS -->

<script src="js/vendor/app.js"></script>

<script src="community/js/community.js"></script>

<script src="js/common/common.js"></script>

<script>

    function queryList () {
        TableManaged.init($("#province").val(),$("#city").val(),$("#district").val(),$("#commName").val());
    }

    function delComm (commId) {
        $.ajax({
            type: "POST",
            url:"communityAction!deleteCommunity.action",
            data:{"commId":commId},
            dataType:"json",
            error: function(request) {
                createAlertMsgMainWin("删除失败");
            },
            success: function(data) {
                if (data.resultCode==1) {
                    createAlertMsgMainWin("删除成功");

//                    TableManaged._table.fnReloadAjax();
                    refreshTable(TableManaged._table);
                } else {
                    createAlertMsgMainWin("删除失败");
                }
            }
        });
    }

    $("#provinceEdit").on('change',function(){
        if ($("#provinceEdit").val()=="") {
            clearOpt('cityEdit','-请先选择省-');
            clearOpt('districtEdit','-请先选择市-');
        } else {
            loadOpts('cityEdit',$("#provinceEdit").val());
            clearOpt('districtEdit','-请先选择市-');
        }
    });
    $("#cityEdit").on("change",function(){
        if ($("#cityEdit").val()=="") {
            clearOpt('districtEdit','-请先选择市-');
        } else {
            loadOpts('districtEdit',$("#cityEdit").val());
        }
    });

    $("#editCommDIV").on("click",function () {

        $("#commnuityForm .modal-header h3").html("添加小区");
        clearData("commnuityForm");

        loadOpts('provinceEdit');
        $("#commnuityForm *").removeClass('error').removeClass('success');
        $("#commnuityForm").validate().resetForm();
        initSelect();
        $("#editComm").modal('show');

        $("#editCommBtn").unbind('click').on("click",function (){

            if (!$("#commnuityForm").valid()) {
                return ;
            }

            $.ajax({
                type: "POST",
                url:"communityAction!addCommunity.action",
                data:$('#commnuityForm').serialize(),
                dataType:"json",
                error: function(request) {
                    createAlertMsgMainWin("添加失败");
                },
                success: function(data) {
                    if (data.resultCode==1) {
                        $("#editComm").modal('hide');
                        createAlertMsgMainWin("添加成功");
//                        TableManaged._table.fnReloadAjax();
                        refreshTable(TableManaged._table);
                    } else {
                        createAlertMsgMainWin("添加失败");
                    }
                }
            });
        });
    });

    function updateComm () {

        oTable = $('#sample_1').dataTable();
        oTable.$('tr').unbind('click').click(function () {
            oTable.$('tr').unbind('click');
            var data = oTable.fnGetData(this);
            loadOpts('provinceEdit');
            loadRelateOpts('cityEdit',data.cityId);
            loadRelateOpts('districtEdit',data.regionalId);
            $("#commnuityForm .modal-header h3").html("修改小区");
            $("#commnuityForm *").removeClass('error').removeClass('success');
            $("#commnuityForm").validate().resetForm();

            var upSign = true;
            $("input[name=commLongLatitude]").val(data.commLongitud+','+data.commLatitude);
            $("input[name=disId]").val(data.disIds);
            initSelect();
            $(document).ajaxStop(function (){
                if (upSign){
                    loadData("commnuityForm",data);
                    $("#editComm").modal("show");
                    upSign = false;
                }
            });

            $("#editCommBtn").unbind('click').on("click",function (){

                if (!$("#commnuityForm").valid()) {
                    return ;
                }

                $.ajax({
                    type: "POST",
                    url:"communityAction!updateCommunity.action",
                    data:$('#commnuityForm').serialize(),
                    dataType:"json",
                    error: function(request) {
                        createAlertMsgMainWin("修改失败");
                    },
                    success: function(data) {
                        if (data.resultCode==1) {
                            $("#editComm").modal('hide');
                            createAlertMsgMainWin("修改成功");

//                            TableManaged._table.fnReloadAjax();
                            refreshTable(TableManaged._table);
                        } else {
                            createAlertMsgMainWin("修改失败");
                        }
                    }
                });
            });
        });
    }

    function detailComm (commId) {
        sessionStorage.setItem("commId", commId);
        window.location.href = "indexAction!setStrutsPage.action?pageFlag=community/commDetail.html";
    }

    function loadRelateOpts(id,param){

        var regId = '';

        if (param) {
            regId = param;
        }

        $.ajax({
            type: "POST",
            url:"regionalAction!queryRelateRegionals.action",
            data:{'regId':regId},
            dataType:"json",
            success: function(data) {
                if (data.resultCode==1) {
                    var opts = '<option value="">-请选择-</option>';
                    var regionalList = data.regionalList;
                    if (regionalList) {
                        for (var i=0;i<regionalList.length;i++) {
                            opts += '<option value="'+regionalList[i].regionalId+'">'+regionalList[i].regionalName+'</option>'
                        }
                    }
                    $("#"+id).html(opts);
                }
            }
        });
    }

    function loadOpts(id,param){

        var parentId = '';

        if (param) {
            parentId = param;
        }

        $.ajax({
            type: "POST",
            url:"regionalAction!queryRegionals.action",
            data:{'parentId':parentId},
            dataType:"json",
            success: function(data) {
                if (data.resultCode==1) {
                    var opts = '<option value="">-请选择-</option>';
                    var regionalList = data.regionalList;
                    if (regionalList) {
                        for (var i=0;i<regionalList.length;i++) {
                            opts += '<option value="'+regionalList[i].regionalId+'">'+regionalList[i].regionalName+'</option>'
                        }
                    }
                    $("#"+id).html(opts);
                }
            }
        });
    }

    function clearOpt (id,addMsg){
        var opts = '<option value="">-请选择-</option>';
        if (addMsg) {
            opts += '<option value="">-'+addMsg+'-</option>'
        }
        $("#"+id).html(opts);
    }

    jQuery(document).ready(function() {

        App.init();

        TableManaged.init();

        FormValidation.init();

        $("#province").on('change',function(){
            if ($("#province").val()=="") {
                clearOpt('city','-请先选择省-');
                clearOpt('district','-请先选择市-');
            } else {
                loadOpts('city',$("#province").val());
                clearOpt('district','-请先选择市-');
            }
        });
        $("#city").on("change",function(){
            if ($("#city").val()=="") {
                clearOpt('district','-请先选择市-');
            } else {
                loadOpts('district',$("#city").val());
            }
        });

        $("#freshBtn").on("click",function(){
//            TableManaged._table.fnReloadAjax();
            refreshTable(TableManaged._table);
        });

        $("#searchBtn").on("click",function (){
            queryList();
        });

        loadOpts('province');



    });

    function initSelect(){

        $("#disId").select2({
            cache:true,
            multiple :true,
            separator:",",
            placeholder: '请选择负责人',
           // minimumInputLength:1,
            //maximumSelectionSize: 5,
            id:function(obj){return obj.disId},
//            createSearchChoice:function (term,data){
//                console.log("createSearchChoice-term:");
//                console.log(term);
//                console.log("createSearchChoice-data:");
//                console.log(data);
//                return {id:data.disId,text:data.disName};
//            },

            ajax: {
                url: "diserAction!queryDiserList.action",
                dataType: 'json',
                quietMillis: 1000 ,
                data: function (term, page) {
//                    console.log("data-term:");console.log(term);
                    return {q: term};
                },
                results: function (data, page) {
//                    console.log("results-data:");console.log(data);
                    return {results: data.results};
                },
                escapeMarkup: function(m) {
                    return m;
                }
            },

            initSelection: function(element, callback) {
//                console.log("initSelection-element:"+callback);
//                console.log(element);
                var id=element.val();
                if (id!=="") {
                    $.ajax("diserAction!queryDiserList.action", {
                        data: {
                            q:id
                        },
                        dataType: "json"
                    }).done(function(data) {
//                        console.log("initSelection-data:");console.log(data);
                        callback(data.results);
                    });
                }
            },
            formatResult: function(obj){
//                console.log("formatResult-obj:");console.log(obj);
                return obj.disName;
            },
            formatSelection:function(obj){
//                console.log("formatSelection-obj:");console.log(obj);
                return obj.disName;
            },
            //dropdownCssClass: "bigdrop",
            escapeMarkup: function (m) { return m; }
        });

    }

</script>
</body>
</html>